using System;
using System.Xml.Serialization;

namespace newtelligence.DasBlog.Runtime
{
	/// <summary>
	/// Summary description for CrossPostServerInfo.
	/// </summary>
	public class PingService
	{
		public enum PingApiType
		{
			Basic,
			Extended
		}

		private string name;
		private string url;
		private string endpoint;
		private PingApiType pingApiType = PingApiType.Basic;

		public string Endpoint
		{
			get { return endpoint; }
			set { endpoint = value; }
		}

		public string Name
		{
			get { return name; }
			set { name = value; }
		}

		public string Url
		{
			get { return url; }
			set { url = value; }
		}

		public PingApiType PingApi
		{
			get { return pingApiType; }
			set { pingApiType = value; }
		}

		[XmlIgnore]
		public string Hyperlink
		{
			get
			{
				return String.Format("<a href=\"{0}\">{1}</a>", this.url, this.name);
			}
		}

		public PingService()
		{
		}

		public static PingServiceCollection GetDefaultPingServices()
		{
			PingServiceCollection pingServiceCollection = new PingServiceCollection();
			pingServiceCollection.Add(GetWebLogsDotCom());
			pingServiceCollection.Add(GetBloGs());
			return pingServiceCollection;
		}

		public static PingService GetWebLogsDotCom()
		{
			PingService ping = new PingService();
			ping.Name = "Weblogs";
			ping.Url = "http://www.weblogs.com";
			ping.Endpoint = "http://rpc.weblogs.com/RPC2";
			ping.PingApi = PingService.PingApiType.Basic;
			return ping;
		}

		public static PingService GetBloGs()
		{
			PingService ping = new PingService();
			ping.Name = "blo.gs";
			ping.Url = "http://www.blo.gs";
			ping.Endpoint = "http://ping.blo.gs/";
			ping.PingApi = PingService.PingApiType.Extended;
			return ping;
		}
	}

	/// <summary>
	/// A collection of elements of type PingServiceInfo
	/// </summary>
	[Serializable]
	public class PingServiceCollection: System.Collections.CollectionBase
	{
		/// <summary>
		/// Initializes a new empty instance of the PingServiceCollection class.
		/// </summary>
		public PingServiceCollection()
		{
			// empty
		}

		/// <summary>
		/// Initializes a new instance of the PingServiceCollection class, containing elements
		/// copied from an array.
		/// </summary>
		/// <param name="items">
		/// The array whose elements are to be added to the new PingServiceCollection.
		/// </param>
		public PingServiceCollection(PingService[] items)
		{
			this.AddRange(items);
		}

		/// <summary>
		/// Initializes a new instance of the PingServiceCollection class, containing elements
		/// copied from another instance of PingServiceCollection
		/// </summary>
		/// <param name="items">
		/// The PingServiceCollection whose elements are to be added to the new PingServiceCollection.
		/// </param>
		public PingServiceCollection(PingServiceCollection items)
		{
			this.AddRange(items);
		}

		/// <summary>
		/// Adds the elements of an array to the end of this PingServiceCollection.
		/// </summary>
		/// <param name="items">
		/// The array whose elements are to be added to the end of this PingServiceCollection.
		/// </param>
		public virtual void AddRange(PingService[] items)
		{
			foreach (PingService item in items)
			{
				this.List.Add(item);
			}
		}

		/// <summary>
		/// Adds the elements of another PingServiceCollection to the end of this PingServiceCollection.
		/// </summary>
		/// <param name="items">
		/// The PingServiceCollection whose elements are to be added to the end of this PingServiceCollection.
		/// </param>
		public virtual void AddRange(PingServiceCollection items)
		{
			foreach (PingService item in items)
			{
				this.List.Add(item);
			}
		}

		/// <summary>
		/// Adds an instance of type PingServiceInfo to the end of this PingServiceCollection.
		/// </summary>
		/// <param name="value">
		/// The PingServiceInfo to be added to the end of this PingServiceCollection.
		/// </param>
		public virtual void Add(PingService value)
		{
			this.List.Add(value);
		}

		/// <summary>
		/// Determines whether a specfic PingServiceInfo value is in this PingServiceCollection.
		/// </summary>
		/// <param name="value">
		/// The PingServiceInfo value to locate in this PingServiceCollection.
		/// </param>
		/// <returns>
		/// true if value is found in this PingServiceCollection;
		/// false otherwise.
		/// </returns>
		public virtual bool Contains(PingService value)
		{
			return this.List.Contains(value);
		}

		/// <summary>
		/// Return the zero-based index of the first occurrence of a specific value
		/// in this PingServiceCollection
		/// </summary>
		/// <param name="value">
		/// The PingServiceInfo value to locate in the PingServiceCollection.
		/// </param>
		/// <returns>
		/// The zero-based index of the first occurrence of the _ELEMENT value if found;
		/// -1 otherwise.
		/// </returns>
		public virtual int IndexOf(PingService value)
		{
			return this.List.IndexOf(value);
		}

		/// <summary>
		/// Inserts an element into the PingServiceCollection at the specified index
		/// </summary>
		/// <param name="index">
		/// The index at which the PingServiceInfo is to be inserted.
		/// </param>
		/// <param name="value">
		/// The PingServiceInfo to insert.
		/// </param>
		public virtual void Insert(int index, PingService value)
		{
			this.List.Insert(index, value);
		}

		/// <summary>
		/// Gets or sets the PingServiceInfo at the given index in this PingServiceCollection.
		/// </summary>
		public virtual PingService this[int index]
		{
			get
			{
				return (PingService) this.List[index];
			}
			set
			{
				this.List[index] = value;
			}
		}

		/// <summary>
		/// Removes the first occurrence of a specific PingServiceInfo from this PingServiceCollection.
		/// </summary>
		/// <param name="value">
		/// The PingServiceInfo value to remove from this PingServiceCollection.
		/// </param>
		public virtual void Remove(PingService value)
		{
			this.List.Remove(value);
		}

		/// <summary>
		/// Type-specific enumeration class, used by PingServiceCollection.GetEnumerator.
		/// </summary>
		public class Enumerator: System.Collections.IEnumerator
		{
			private System.Collections.IEnumerator wrapped;

			public Enumerator(PingServiceCollection collection)
			{
				this.wrapped = ((System.Collections.CollectionBase)collection).GetEnumerator();
			}

			public PingService Current
			{
				get
				{
					return (PingService) (this.wrapped.Current);
				}
			}

			object System.Collections.IEnumerator.Current
			{
				get
				{
					return (PingService) (this.wrapped.Current);
				}
			}

			public bool MoveNext()
			{
				return this.wrapped.MoveNext();
			}

			public void Reset()
			{
				this.wrapped.Reset();
			}
		}

		/// <summary>
		/// Returns an enumerator that can iterate through the elements of this PingServiceCollection.
		/// </summary>
		/// <returns>
		/// An object that implements System.Collections.IEnumerator.
		/// </returns>        
		public new virtual PingServiceCollection.Enumerator GetEnumerator()
		{
			return new PingServiceCollection.Enumerator(this);
		}
	}
}
